<template>
  <el-container>
    <el-header class="sa-header">
      <div class="sa-title-top">
        <div class="title-text">如需新增商品，需先申请类目（已申请过的类目除外）</div>
        <!-- <div class="title-btn">申请新类目</div> -->
      </div>
      <el-tabs class="sa-tabs" v-model="filterParams.data.audit" @tab-change="getData(1)">
        <el-tab-pane
          v-for="(item,index) in statusList"
          :key="index"
          :label="item.name"
          :name="item.type"
        ></el-tab-pane>
      </el-tabs>
      <div class="sa-title sa-flex sa-row-between">
        <div class="label sa-flex">
          <span class="left"></span>
          <search-condition
            :conditionLabel="filterParams.conditionLabel"
            @deleteFilter="deleteFilter"
          ></search-condition>
        </div>
        <div>
          <el-button
            v-auth="'seller.admin.application.list'"
            class="sa-button-refresh"
            icon="RefreshRight"
            @click="getData()"
          ></el-button>
          <el-button class="sa-button-refresh" icon="Search" @click="openFilter"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="sa-p-0" v-loading="table.loading">
      <el-table class="sa-table" height="100%" :data="table.data" stripe>
        <template #empty>
          <sa-empty />
        </template>
        <!-- <el-table-column sortable="custom" prop="id" label="ID" min-width="80" /> -->
        <el-table-column prop="merchant_name" label="类目" min-width="150" align="center" />
        <el-table-column prop="create_time" label="申请时间" min-width="150" align="center" />
        <el-table-column prop="status" label="状态" min-width="120" align="center" />
        <el-table-column fixed="right" label="操作" min-width="150">
          <template #default="scope">
            <el-button
              v-auth="'seller.admin.application.audit'"
              class="is-link"
              type="primary"
              @click="audit(scope.row)"
            >发布商品
            </el-button>
            <el-button
              v-auth="'seller.admin.application.details'"
              class="is-link"
              type="primary"
              @click="see(scope.row)"
            >删除类目
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <sa-view-bar>
      <template #right>
        <sa-pagination :pageData="pageData" @updateFn="getData" />
      </template>
    </sa-view-bar>
  </el-container>
</template>
<script>
  export default {
    name: 'seller.admin.info',
  };
</script>

<script setup>
  import { onMounted, reactive } from 'vue';
  import { api } from '../info.service';
  import { usePagination, useModal } from '@/sheep/hooks';
  import { useSearch } from '@/sheep/components/sa-table/sa-search/useSearch';
  import { composeFilter } from '@/sheep/utils';
  import { useRoute } from 'vue-router';
  import details from './details.vue';
  import _ from 'lodash';
  import code from './code.vue';

  const statusList = [
    { name: '生效中', type: 'all' },
    { name: '审核中', type: '0' },
    { name: '审核不通过', type: '1' },
    { name: '已撤回', type: '2' }];
    const statusList2 = [
    { name: '入驻', type: '1' },
    { name: '进件', type: '2' },
   ];

  const route = useRoute();
  const emit = defineEmits(['modalCallBack']);

  const filterParams = reactive({
    tools: {
      merchant_name: {
        type: 'tinput',
        field: 'merchant_name',
        value: '',
        label: '类目名称',
        placeholder: '请输入类目名称',
      },
      serve: {
        type: 'tselect',
        label: '类目状态',
        field: 'serve',
        value: '',
        options: {
          data: [
            {
              label: '全部',
              value: 2,
            },
            {
              label: '启用',
              value: 1,
            },
            {
              label: '停用',
              value: 3,
            },
          ],
        },
      },
    },
    data: {
      type:'1',
      audit: 'all',
      serve: '',
      user: { field: 'user.nickname', value: '' },
      create_time: route.query.create_time || [],
    },
    conditionLabel: {},
  });

  const { openFilter, deleteFilter } = useSearch({ filterParams, getData });

  const table = reactive({
    loading: false,
    data: [],
  });

  const { pageData } = usePagination();

  const calcStatus = (row) => {
    if (row.status === 0) return '待审核';
    if (row.status === 1) return '已审核';
    if (row.status === 2) return '已驳回';
  };

  async function getData(page) {
    // table.loading = true;
    // if (page) pageData.page = page;
    // let tempSearch = _.cloneDeep(filterParams.data);
    // let search = composeFilter(tempSearch, {
    //   'user.nickname': 'like',
    //   'user.id': 'like',
    //   'user.merchant_name': 'like',
    //   create_time: 'range',
    //   serve: 'like',
    // });

    // if (!_.isEmpty(search)) {
    //   if (_.includes(search.search, 'audit')) {
    //     search.search = _.replace(search.search, /audit/, 'status');
    //   }
    // }
    // const { error, data } = await api.list({
    //   page: pageData.page,
    //   list_rows: pageData.list_rows,
    //   ...search,
    // });
    // if (error === 0) {
    //   table.data = data.data;
    //   pageData.page = data.current_page;
    //   pageData.list_rows = data.per_page;
    //   pageData.total = data.total;
    // }
    // table.loading = false;
    table.loading = true;
    table.data = [
      {
        merchant_name:'一级类目 > 二级类目 > 三级类目',
        create_time:'2025/05/05 11:11:11',
        status:'审核通过',
      },
      {
        merchant_name:'一级类目 > 二级类目 > 三级类目',
        create_time:'2025/05/05 11:11:11',
        status:'审核通过',
      },
      {
        merchant_name:'一级类目 > 二级类目 > 三级类目',
        create_time:'2025/05/05 11:11:11',
        status:'审核通过',
      },
      {
        merchant_name:'一级类目 > 二级类目 > 三级类目',
        create_time:'2025/05/05 11:11:11',
        status:'审核通过',
      },
    ]
    pageData.page = 1;
    pageData.list_rows = 1;
    pageData.total = 4;
    table.loading = false;
  }


  const openCode = (row) => {
    useModal(
      code,
      {
        title: '填写资料',
        id: row.id,
        class:'sa-width-500'
      },
      {
        confirm: () => {
          setTimeout(() => {
            emit('modalCallBack', { event: 'confirm' });
          }, 200);
        },
      },
    );
  };
  //审核
  const audit = (data) => {
    useModal(
      details,
      {
        title: '审核',
        id: data.id,
      },
      {
        confirm: () => {
          getData();
        },
      },
    );
  };

  const see = (item) => {
    useModal(
      details,
      {
        title: '申请详情',
        id: item.id,
      },
      {
        confirm: () => {
          getData();
        },
      },
    );
  };

  onMounted(() => {
    getData();
  });

</script>
<style lang="scss" scoped>
  .success {
    color: #67C23A;
  }

  .fail {
    color: #FA5151;
  }

  .ing {
    color: #FFC300;
  }
  .el-tabs__active-bar{
    background-color: transparent !important;
  }
  .el-tabs__item.is-active{
    color: #000000 !important;
  }
  .el-tabs__item{
    color: #999999 !important;
  }
  .el-tabs__item:hover{
    color: #000000 !important;
  }
  .sa-title-top{
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    align-items: center;
    border-bottom: 20px solid #EEEEEE;
    .title-text{
      font-size: 14px;
      font-family: Source Han Sans;
      font-weight: bold;
    }
    .title-btn{
      font-size: 12px;
      background-color: #515151;
      color: #FFFFFF;
      display: flex;
      height: 30px;
      padding: 0 5px;
      justify-content: center;
      align-items: center;
    }
  }
</style>